#include "vehplateutils.h"

VehPlateUtils::VehPlateUtils(QObject *parent) : QObject(parent)
{

}

VehPlateUtils::~VehPlateUtils()
{

}

QString VehPlateUtils::getVehPlateColorDesc(int nCode)
{
    switch (nCode) {
    case 0:
        return "蓝";
        break;
    case 1:
        return "黄";
        break;
    case 2:
        return "黑";
        break;
    case 3:
        return "白";
        break;
    default:
        return "";
        break;
    }
}

QString VehPlateUtils::getVehicleLicencePlateColorAndNumber(int nPlateColor, const QString &sPlateNum)
{
    if (sPlateNum.length()==0)
    {
        // 无车牌时，车牌颜色也无效
        return sPlateNum;
    }
    QString sFullPlate(getVehPlateColorDesc(nPlateColor));
    sFullPlate.append(sPlateNum);
    return sFullPlate;
}

bool VehPlateUtils::isValidVehPlate(int nPlateColor, const QString &sPlateNum)
{
    return (sPlateNum.length()>0) &&
            (nPlateColor>=0) &&
            (nPlateColor<=3);
}

int VehPlateUtils::seprateVehPlateColorAndNum(QString &sPlateNum, const QString &sPlateNumWithColor)
{
    int vehPlateColor=-1;
    if (sPlateNumWithColor.startsWith("蓝"))
    {
        vehPlateColor=0;
    }
    else if (sPlateNumWithColor.startsWith("黄"))
    {
        vehPlateColor=1;
    }
    else if (sPlateNumWithColor.startsWith("黑"))
    {
        vehPlateColor=2;
    }
    else if (sPlateNumWithColor.startsWith("白"))
    {
        vehPlateColor=3;
    }

    if (vehPlateColor<0)
    {
        sPlateNum=sPlateNumWithColor;
    }
    else
    {
        sPlateNum=sPlateNumWithColor.mid(1);
    }
    return vehPlateColor;
}
